﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace DataAccess.Operate
{
    public class DA_Report_Plan_Inherit:SqlInteractionBase
    {
        

        public DataSet Report_Search(string sSql)
        {

            SqlCommand cmdToExecute = new SqlCommand();
            SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);
            DataSet ds = new DataSet();

            cmdToExecute.CommandText = sSql;
            cmdToExecute.CommandType = CommandType.Text;

            try
            {
                cmdToExecute.Connection = _mainConnection;
                if (_mainConnectionIsCreatedLocal)
                {
                    _mainConnection.Open();
                }
                else
                {
                    if (_mainConnectionProvider.IsTransactionPending)
                    {
                        cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
                    }
                }

                adapter.Fill(ds);

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                if (_mainConnectionIsCreatedLocal)
                {
                    _mainConnection.Close();
                }

                cmdToExecute.Dispose();

                adapter.Dispose();
            }

            return ds;
        }

        /// <summary>
        /// 审核
        /// </summary>
        /// <param name="id"></param>
        /// <param name="audit"></param>
        /// <returns></returns>
        public bool AuditByID(string id, string audit)
        {
            string sSql = "update t_Report_Plan set Report_Plan_Audit=" + audit + " where Report_Plan_ID='"+id+"'";
            return RunNoneSQL(sSql);
        }

        /// <summary>
        /// 获取下一步审批人的工号和姓名
        /// </summary>
        /// <param name="purview"></param>
        /// <param name="projectID"></param>
        /// <returns></returns>
        public DataTable GetCodeAndName(string purview, string projectID)
        {

            string sSql = "select EmployeeName,Code from [GZS-FIN02].AIS20050623105602.dbo.v_Report_WorkInfo where EM_ID in(SELECT Login_KDHRID FROM [DB_EcSystemPowerManage].[dbo].[t_System_Login] where  Login_ID in(select PermissionForECSM_LoginID from [DB_EcSystemPowerManage].[dbo].[t_User_PermissionForECSM] where PermissionForECSM_Module_Purview like '%"+purview+"%' and PermissionForECSM_LoginID in(select User_BuildingForECSM_LoginID from [DB_EcSystemPowerManage].[dbo].[t_User_BuildingForECSM] where User_BuildingForECSM_BuildingID in (SELECT Project_Hr_KDNameID FROM [DB_EcSalseManage].[dbo].[t_Project_Hr] where Project_Hr_MainID='"+projectID+"'))))";

            //string sSql = "select Project_DirecterCode,Project_Directer,Project_Directer1Code,Project_Directer1,Project_ManagerCode,Project_Manager,Project_Business,Project_BusinessCode,Project_DepartmentHead,Project_DepartmentHeadCode  from  t_Project where Project_ID='"+projectID+"'";
            return RunSQL(sSql).Tables[0];
        }

         

        
    }
}